<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:86:"D:\vue\xiangcun\ruoyi\webeditor\web/../source/application/admin\view\settings\logs.php";i:1760207829;s:85:"D:\vue\xiangcun\ruoyi\webeditor\source\application\admin\view\layout\layui_header.php";i:1760184068;s:85:"D:\vue\xiangcun\ruoyi\webeditor\source\application\admin\view\layout\layui_footer.php";i:1750747208;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo (isset($title) && ($title !== '')?$title:'精简版权限管理系统'); ?> - 管理后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="/assets/common/css/layui.css" rel="stylesheet">
    <link rel="stylesheet" href="/assets/common/font-awesome.min.css">
    <style>
        /* 自定义样式补充 */
        .layui-logo {
            color: #fff;
            font-size: 18px;
            font-weight: bold;
        }
        
        .layui-nav-tree .layui-nav-item > a {
            height: 50px;
            line-height: 50px;
        }
        
        .layui-nav-tree .layui-nav-child dd a {
            height: 40px;
            line-height: 40px;
        }
        
        .layui-body {
            overflow-y: auto;
        }
        
        .main-content {
            padding: 20px;
            min-height: calc(100vh - 140px);
        }
        
        .page-header {
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .page-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin: 0 0 8px 0;
        }
        
        .page-subtitle {
            color: #666;
            font-size: 14px;
            margin: 0;
        }
        
        .widget {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .widget-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .widget-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }
        
        .widget-actions {
            display: flex;
            gap: 10px;
        }
        
        .btn-widget {
            padding: 6px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            background: #fff;
            color: #666;
            text-decoration: none;
            font-size: 12px;
            transition: all 0.2s;
            cursor: pointer;
        }
        
        .btn-widget:hover {
            background: #1890ff;
            color: #fff;
            border-color: #1890ff;
        }
        
        /* 移动端适配 */
        @media (max-width: 768px) {
            .main-content {
                padding: 15px;
            }
            
            .widget {
                padding: 15px;
            }
            
            .widget-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }
            
            .widget-actions {
                width: 100%;
            }
            
            .btn-widget {
                flex: 1;
                text-align: center;
            }
            
            /* 移动端左侧菜单默认隐藏 */
            .layui-side {
                left: -200px !important;
                transition: left 0.3s ease;
                z-index: 1001;
            }
            
            /* 移动端菜单展开状态 */
            .layui-layout-admin.mobile-menu-open .layui-side,
            .layui-side.mobile-menu-open {
                left: 0 !important;
            }
            
            /* 移动端内容区域调整 */
            .layui-body {
                left: 0 !important;
                transition: margin-left 0.3s ease;
            }
            
            /* 移动端遮罩层 */
            .mobile-menu-overlay {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.5);
                z-index: 1000;
                display: none;
                opacity: 0;
                transition: opacity 0.3s ease;
            }
            
            .layui-layout-admin.mobile-menu-open .mobile-menu-overlay {
                display: block;
                opacity: 1;
            }
            
            /* 确保移动端菜单按钮可见 */
            .layui-nav .layui-nav-item[lay-header-event="menuLeft"] {
                display: inline-block !important;
            }
            
            /* 移动端菜单按钮样式 */
            .layui-nav .layui-nav-item[lay-header-event="menuLeft"] i {
                font-size: 18px;
                color: #fff;
            }
        }
        
        /* 移动端菜单按钮样式优化 */
        .layui-nav .layui-nav-item[lay-header-event="menuLeft"] {
            cursor: pointer;
        }
        
        .layui-nav .layui-nav-item[lay-header-event="menuLeft"]:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }
    </style>
</head>
<body>
<script src="/assets/common/layui.js"></script>
<script>
    var $ = layui.jquery;
</script>
<div class="layui-layout layui-layout-admin">
    <!-- 头部区域 -->
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs">精简版权限管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>
            <!-- 移动端标题 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" style="color: #fff; line-height: 60px; padding-left: 15px;">
                权限管理系统
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-user"></i>
                    <?php
                    use think\Session;
                    $adminInfo = Session::get('admin_info');
                    echo $adminInfo ? $adminInfo['real_name'] ?: $adminInfo['username'] : '未知用户';
                    ?>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="<?php echo url('/admin/settings/profile'); ?>">个人信息</a></dd>
                    <dd><a href="<?php echo url('/admin/settings/basic'); ?>">系统设置</a></dd>
                    <dd><a href="<?php echo url('/admin/settings/changePassword'); ?>">修改密码</a></dd>
                    <dd><a href="javascript:;" id="logout-btn">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    
    <!-- 左侧导航区域 -->
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="nav">
                <?php
                use app\common\MenuHelper;
                echo MenuHelper::generateMenuHTML($current_page ?? '', $current_subpage ?? '');
                ?>
            </ul>
        </div>
    </div>
    

    
    <!-- 移动端菜单遮罩层 -->
    <div class="mobile-menu-overlay"></div>
    
    <script src="/assets/common/js/layui.js"></script>
    <script>
    // 退出登录功能
    layui.use(['layer', 'jquery'], function(){
        var layer = layui.layer;
        var $ = layui.jquery;
        
        // 退出登录
        $(document).on('click', '#logout-btn', function(e){
            e.preventDefault();
            layer.confirm('确定要退出登录吗？', {
                icon: 3,
                title: '提示'
            }, function(index){
                $.ajax({
                    url: '/admin/login/logout',
                    type: 'POST',
                    dataType: 'json',
                    success: function(res) {
                        layer.close(index);
                        if (res.code === 0) {
                            layer.msg(res.msg || '退出成功', {icon: 1, time: 1000}, function(){
                                window.location.href = res.redirect || '/admin/login';
                            });
                        } else {
                            layer.msg(res.msg || '退出失败', {icon: 2});
                        }
                    },
                    error: function() {
                        layer.close(index);
                        layer.msg('网络错误，请稍后重试', {icon: 2});
                    }
                });
            });
            return false;
        });
    });
    </script>
    
    <!-- 内容主体区域 -->
    <div class="layui-body">

<!-- 主要内容 -->
<div class="main-content">
    <div class="page-header">
        <h1 class="page-title">操作日志</h1>
        <p class="page-subtitle">查看系统操作记录和安全日志</p>
    </div>

    <!-- 日志统计卡片 -->
    <div class="layui-row layui-col-space20">
        <div class="layui-col-md3 layui-col-sm6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="fas fa-file-alt" style="color: #10b981; margin-right: 8px;"></i>
                    今日日志
                </div>
                <div class="layui-card-body">
                    <h2 style="margin: 0; color: #10b981; font-size: 28px;" id="todayLogs">0</h2>
                    <p style="margin: 5px 0 0 0; color: #666; font-size: 12px;">条记录</p>
                </div>
            </div>
        </div>
        <div class="layui-col-md3 layui-col-sm6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="fas fa-user-shield" style="color: #3b82f6; margin-right: 8px;"></i>
                    登录日志
                </div>
                <div class="layui-card-body">
                    <h2 style="margin: 0; color: #3b82f6; font-size: 28px;" id="loginLogs">0</h2>
                    <p style="margin: 5px 0 0 0; color: #666; font-size: 12px;">登录次数</p>
                </div>
            </div>
        </div>
        <div class="layui-col-md3 layui-col-sm6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="fas fa-exclamation-triangle" style="color: #f59e0b; margin-right: 8px;"></i>
                    异常操作
                </div>
                <div class="layui-card-body">
                    <h2 style="margin: 0; color: #f59e0b; font-size: 28px;" id="errorLogs">0</h2>
                    <p style="margin: 5px 0 0 0; color: #666; font-size: 12px;">异常记录</p>
                </div>
            </div>
        </div>
        <div class="layui-col-md3 layui-col-sm6">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="fas fa-database" style="color: #ef4444; margin-right: 8px;"></i>
                    日志总数
                </div>
                <div class="layui-card-body">
                    <h2 style="margin: 0; color: #ef4444; font-size: 28px;" id="totalLogs">0</h2>
                    <p style="margin: 5px 0 0 0; color: #666; font-size: 12px;">历史记录</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 日志管理表格 -->
    <div class="layui-card">
        <div class="layui-card-header">
            <h3>操作日志</h3>
        </div>
        <div class="layui-card-body">
            <!-- 搜索和操作栏 -->
            <div class="layui-row layui-col-space15" style="margin-bottom: 15px;">
                <div class="layui-col-md4">
                    <div class="layui-input-group">
                        <input type="text" id="searchInput" placeholder="搜索用户名或操作内容" class="layui-input">
                        <div class="layui-input-split layui-input-suffix">
                            <button class="layui-btn layui-btn-primary" onclick="searchLogs()">
                                <i class="fas fa-search"></i>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md8" style="text-align: right;">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="exportLogs()">
                        <i class="fas fa-download"></i>
                        导出日志
                    </button>
                    <button type="button" class="layui-btn layui-btn-warm" onclick="clearOldLogs()">
                        <i class="fas fa-trash-alt"></i>
                        清理过期日志
                    </button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="refreshLogs()">
                        <i class="fas fa-sync"></i>
                        刷新
                    </button>
                </div>
            </div>

            <!-- 过滤器 -->
            <div class="layui-form" style="margin-bottom: 15px;">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md2">
                        <select name="moduleFilter" lay-filter="moduleFilter">
                            <option value="">所有模块</option>
                            <option value="login">登录模块</option>
                            <option value="vehicle">车辆管理</option>
                            <option value="payment">缴费管理</option>

                            <option value="settings">系统设置</option>
                            <option value="blacklist">黑名单</option>
                        </select>
                    </div>
                    <div class="layui-col-md2">
                        <select name="actionFilter" lay-filter="actionFilter">
                            <option value="">所有操作</option>
                            <option value="create">新增</option>
                            <option value="update">修改</option>
                            <option value="delete">删除</option>
                            <option value="login">登录</option>
                            <option value="logout">登出</option>
                            <option value="view">查看</option>
                        </select>
                    </div>
                    <div class="layui-col-md2">
                        <select name="levelFilter" lay-filter="levelFilter">
                            <option value="">所有级别</option>
                            <option value="info">信息</option>
                            <option value="warning">警告</option>
                            <option value="error">错误</option>
                            <option value="debug">调试</option>
                        </select>
                    </div>
                    <div class="layui-col-md3">
                        <input type="text" name="dateRange" placeholder="选择时间范围" class="layui-input" id="dateRange">
                    </div>
                    <div class="layui-col-md3">
                        <input type="text" name="ipFilter" placeholder="IP地址过滤" class="layui-input">
                    </div>
                </div>
            </div>

            <!-- 日志表格 -->
            <table id="logsTable" lay-filter="logsTable"></table>
        </div>
    </div>
</div>

<!-- 操作按钮模板 -->
<script type="text/html" id="logActionBar">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">详情</a>
</script>

<!-- 日志级别模板 -->
<script type="text/html" id="levelTpl">
    {{# if(d.level == 'info') { }}
        <span class="layui-badge layui-bg-blue">信息</span>
    {{# } else if(d.level == 'warning') { }}
        <span class="layui-badge layui-bg-orange">警告</span>
    {{# } else if(d.level == 'error') { }}
        <span class="layui-badge layui-bg-red">错误</span>
    {{# } else { }}
        <span class="layui-badge layui-bg-gray">调试</span>
    {{# } }}
</script>

<script src="/assets/common/layui.js"></script>
<script>
layui.use(['table', 'form', 'layer', 'laydate','jquery'], function(){
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var $ = layui.jquery;
    // 渲染日期范围选择器
    laydate.render({
        elem: '#dateRange',
        type: 'datetime',
        range: true
    });
    
    // 渲染日志表格
    table.render({
        elem: '#logsTable',
        url: '/admin/settings/getLogsList',
        page: true,
        id: 'logsTable',
        height: 'full-320',
        initSort: {
            field: 'created_at',
            type: 'desc'
        },
        cols: [[
            {field: 'id', title: 'ID', width: 80, sort: true},
            {field: 'user_name', title: '操作用户', width: 120},
            {field: 'url', title: '模块'},
            {field: 'url_name', title: '操作类型', width: 100},
            {field: 'ip', title: 'IP地址', width: 130},
            {field: 'user_agent', title: '浏览器', width: 200, hide: true},
            {field: 'level', title: '日志级别', width: 100, templet: '#levelTpl'},
            {field: 'create_time', title: '操作时间', width: 160, sort: true, templet:function(d){
                return layui.util.toDateString(d.create_time + '000','yyyy-MM-dd HH:mm:ss');
            }},
            {title: '操作', width: 100, toolbar: '#logActionBar', fixed: 'right'}
        ]],
        done: function(res) {
            // 更新统计数据
            updateLogStats(res.data);
        }
    });
    
    // 监听表格工具条
    table.on('tool(logsTable)', function(obj){
        var data = obj.data;
        if(obj.event === 'detail'){
            showLogDetail(data);
        }
    });
    
    // 监听过滤器变化
    form.on('select(moduleFilter)', function(data){
        reloadTable();
    });
    
    form.on('select(actionFilter)', function(data){
        reloadTable();
    });
    
    form.on('select(levelFilter)', function(data){
        reloadTable();
    });
    
    // 搜索功能
    window.searchLogs = function() {
        reloadTable();
    };
    
    // 刷新功能
    window.refreshLogs = function() {
        layer.msg('正在刷新...', {icon: 16});
        table.reload('logsTable');
    };
    
    // 导出日志
    window.exportLogs = function() {
        layer.confirm('确定要导出当前筛选条件下的日志吗？', {
            icon: 3,
            title: '确认导出'
        }, function(index) {
            layer.msg('正在导出，请稍候...', {icon: 16});
            
            // 获取当前筛选条件
            var params = getCurrentFilters();
            
            // 创建下载链接
            var downloadUrl = '/admin/settings/logs/export?' + new URLSearchParams(params).toString();
            
            // 模拟下载
            setTimeout(function() {
                layer.msg('导出成功！', {icon: 1});
                // 实际项目中这里应该触发下载
                // window.open(downloadUrl);
                layer.close(index);
            }, 2000);
        });
    };
    
    // 清理过期日志
    window.clearOldLogs = function() {
        layer.open({
            type: 1,
            title: '清理过期日志',
            area: ['400px', '300px'],
            content: `
                <div style="padding: 20px;">
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label">保留天数</label>
                            <div class="layui-input-block">
                                <input type="number" name="days" value="30" min="7" max="365" class="layui-input">
                                <div class="layui-form-mid layui-word-aux">天前的日志将被删除</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" onclick="confirmClearLogs()">确认清理</button>
                                <button type="button" class="layui-btn layui-btn-primary" onclick="layer.closeAll()">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            `
        });
    };
    
    // 确认清理日志
    window.confirmClearLogs = function() {
        var days = document.querySelector('input[name="days"]').value;
        layer.confirm('确定要删除 ' + days + ' 天前的日志吗？此操作不可恢复！', {
            icon: 3,
            title: '确认清理'
        }, function(index) {
            layer.msg('正在清理日志...', {icon: 16});
            
            // 这里发送AJAX请求清理日志
            setTimeout(function() {
                layer.msg('清理完成！共清理了 ' + Math.floor(Math.random() * 1000) + ' 条日志', {icon: 1});
                table.reload('logsTable');
                layer.closeAll();
            }, 2000);
        });
    };
    
    // 显示日志详情
    function showLogDetail(data) {
        var content = `
            <div style="padding: 20px; line-height: 2;">
                <table class="layui-table" lay-size="sm">
                    <tr><td width="120"><strong>日志ID:</strong></td><td>${data.id}</td></tr>
                    <tr><td><strong>操作用户:</strong></td><td>${data.user_id}</td></tr>
                    <tr><td><strong>操作模块:</strong></td><td>${data.url}</td></tr>
                    <tr><td><strong>操作类型:</strong></td><td>${data.url_name}</td></tr>
                    <tr><td><strong>IP地址:</strong></td><td>${data.ip}</td></tr>
                    <tr><td><strong>日志级别:</strong></td><td>${data.level}</td></tr>
                    <tr><td><strong>操作时间:</strong></td><td>${data.create_time}</td></tr>
                </table>
            </div>
        `;
        
        layer.open({
            type: 1,
            title: '日志详情',
            area: ['800px', '600px'],
            content: content,
            btn: ['关闭'],
            yes: function(index) {
                layer.close(index);
            }
        });
    }
    
    // 重新加载表格
    function reloadTable() {
        var params = getCurrentFilters();
        
        table.reload('logsTable', {
            where: params
        });
    }
    
    // 获取当前筛选条件
    function getCurrentFilters() {
        var searchText = document.getElementById('searchInput').value;
        var formData = form.val('form');
        
        return {
            search: searchText,
            module: formData.moduleFilter,
            action: formData.actionFilter,
            level: formData.levelFilter,
            date_range: formData.dateRange,
            ip: formData.ipFilter
        };
    }
    
    // 更新统计数据
    function updateLogStats(data) {
        var today = new Date().toDateString();
        var todayCount = data.filter(item => {
            var itemDate = new Date(item.created_at).toDateString();
            return itemDate === today;
        }).length;
        
        var loginCount = data.filter(item => item.action === 'login' || item.action === 'logout').length;
        var errorCount = data.filter(item => item.level === 'error').length;
        var totalCount = data.length;
        
        document.getElementById('todayLogs').textContent = todayCount;
        document.getElementById('loginLogs').textContent = loginCount;
        document.getElementById('errorLogs').textContent = errorCount;
        document.getElementById('totalLogs').textContent = totalCount;
    }
    
    // 从API获取并更新统计数据
    function updateStatsFromAPI() {
        $.get('/admin/settings/todayStats', function(res) {
            if (res.code === 0) {
                var stats = res.data;
                document.getElementById('todayLogs').textContent = stats.total;
                document.getElementById('loginLogs').textContent = stats.operators; // 使用操作人数代替登录次数
                document.getElementById('errorLogs').textContent = stats.failed;
                document.getElementById('totalLogs').textContent = stats.total;
            }
        });
    }
    
    // 页面加载完成后立即更新统计数据
    $(document).ready(function() {
        updateStatsFromAPI();
        
        // 每分钟更新一次统计数据
        setInterval(updateStatsFromAPI, 60000);
    });
    
    // 绑定搜索回车事件
    document.getElementById('searchInput').addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            searchLogs();
        }
    });
    
    // 监听IP地址输入框
    document.querySelector('input[name="ipFilter"]').addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            reloadTable();
        }
    });
    
    console.log('操作日志页面加载完成');
    
    // 修复菜单展开问题
    setTimeout(function() {
        console.log('开始修复菜单...');
        
        // 检查当前页面菜单结构
        $('.layui-nav-tree .layui-nav-item').each(function(i) {
            var $item = $(this);
            var $link = $item.children('a');
            var linkText = $link.text().trim();
            var linkHref = $link.attr('href');
            var hasChild = $item.children('.layui-nav-child, dl').length > 0;
            
            console.log('菜单项' + i + ':', linkText, 'href:', linkHref, '有子菜单:', hasChild);
            
            // 如果是javascript:;链接但没有子菜单，则添加子菜单
            if (linkHref === 'javascript:;' && !hasChild) {
                if (linkText.includes('车辆管理')) {
                    $item.append(`
                        <dl class="layui-nav-child">
                            <dd><a href="/admin/vehicle/list">车辆列表</a></dd>
                            <dd><a href="/admin/vehicle/add">新增车辆</a></dd>
                            <dd><a href="/admin/vehicle/temporary">临时车辆</a></dd>
                        </dl>
                    `);
                    console.log('添加车辆管理子菜单');
                } else if (linkText.includes('缴费管理')) {
                    $item.append(`
                        <dl class="layui-nav-child">
                            <dd><a href="/admin/payment/list">缴费记录</a></dd>
                            <dd><a href="/admin/payment/orders">订单管理</a></dd>
                            <dd><a href="/admin/payment/settings">缴费设置</a></dd>
                        </dl>
                    `);
                    console.log('添加缴费管理子菜单');
                } else if (linkText.includes('设备管理')) {
                    $item.append(`
                        <dl class="layui-nav-child">
                            
                        </dl>
                    `);
                    console.log('添加设备管理子菜单');
                } else if (linkText.includes('统计报表')) {
                    $item.append(`
                        <dl class="layui-nav-child">
                            <dd><a href="/admin/report/income">收入统计</a></dd>
                            <dd><a href="/admin/report/vehicle">车辆统计</a></dd>
    
                        </dl>
                    `);
                    console.log('添加统计报表子菜单');
                }
            }
        });
        
        // 重新绑定菜单点击事件
        // 先解除layui自带的菜单事件
        layui.element.on('nav(nav)', function(){
            return false; // 阻止layui默认事件
        });
        
        // 绑定自定义菜单点击事件
        $('.layui-nav-tree .layui-nav-item > a[href="javascript:;"]').off('click.menufix').on('click.menufix', function(e) {
            e.preventDefault();
            e.stopPropagation();
            
            var $this = $(this);
            var $item = $this.parent('.layui-nav-item');
            var $children = $item.children('.layui-nav-child');
            var menuText = $this.clone().children().remove().end().text().trim(); // 获取纯文本，排除图标
            
            console.log('菜单点击:', menuText, '子菜单数量:', $children.length);
            
            if ($children.length > 0) {
                if ($item.hasClass('layui-nav-itemed')) {
                    $item.removeClass('layui-nav-itemed');
                    console.log('关闭菜单:', menuText);
                } else {
                    // 先关闭其他展开的菜单
                    $('.layui-nav-tree .layui-nav-item').removeClass('layui-nav-itemed');
                    // 展开当前菜单
                    $item.addClass('layui-nav-itemed');
                    console.log('展开菜单:', menuText);
                }
            }
            
            return false;
        });
        
        console.log('菜单修复完成');
    }, 1000);
});
</script>

</div>
    
    <!-- 底部固定区域 -->
    <div class="layui-footer">
        © 2025 大头停车管理系统 - 智能停车解决方案
    </div>
</div>

<!-- <script src="/assets/common/layui.js"></script> -->
<script>
//JS 
layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element;
    var layer = layui.layer;
    var util = layui.util;
    
    // 重新渲染元素，确保菜单正常工作
    element.render('nav');
    
    //头部事件
    util.event('lay-header-event', {
        menuLeft: function(othis){ // 左侧菜单事件 - 移动端菜单切换
            toggleMobileMenu();
        },
        menuRight: function(){  // 右侧菜单事件
            layer.open({
                type: 1,
                title: '更多',
                content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                area: ['260px', '100%'],
                offset: 'rt', // 右上角
                anim: 'slideLeft', // 从右侧抽屉滑出
                shadeClose: true,
                scrollbar: false
            });
        }
    });
    
    // 移动端菜单控制函数
    function toggleMobileMenu() {
        var $layout = $('.layui-layout-admin');
        var $side = $('.layui-side');
        var $overlay = $('.mobile-menu-overlay');
        
        console.log('toggleMobileMenu 被调用');
        
        if ($layout.hasClass('mobile-menu-open')) {
            // 关闭菜单
            $layout.removeClass('mobile-menu-open');
            $side.removeClass('mobile-menu-open');
            console.log('关闭移动端菜单');
        } else {
            // 打开菜单
            $layout.addClass('mobile-menu-open');
            $side.addClass('mobile-menu-open');
            console.log('打开移动端菜单');
        }
    }
    
    // 点击遮罩层关闭菜单
    $(document).on('click', '.mobile-menu-overlay', function() {
        console.log('点击遮罩层关闭菜单');
        $('.layui-layout-admin').removeClass('mobile-menu-open');
        $('.layui-side').removeClass('mobile-menu-open');
    });
    
    // 监听窗口大小变化，当屏幕变大时自动关闭移动端菜单
    $(window).on('resize', function() {
        if ($(window).width() > 768) {
            console.log('屏幕变大，关闭移动端菜单');
            $('.layui-layout-admin').removeClass('mobile-menu-open');
            $('.layui-side').removeClass('mobile-menu-open');
        }
    });
    
    // 添加移动端菜单项点击后自动关闭菜单的功能
    $(document).on('click', '.layui-side .layui-nav a', function(e) {
        if ($(window).width() <= 768) {
            var href = $(this).attr('href');
            if (href && href !== 'javascript:;' && href.indexOf('#') !== 0) {
                setTimeout(function() {
                    $('.layui-layout-admin').removeClass('mobile-menu-open');
                    $('.layui-side').removeClass('mobile-menu-open');
                }, 200);
            }
        }
    });
    
    // 设置当前页面导航高亮
    var currentPath = window.location.pathname;
    var currentUrl = window.location.href;
    
    // 获取当前页面的控制器和方法
    var urlParams = new URLSearchParams(window.location.search);
    var currentController = '';
    var currentAction = '';
    
    // 解析URL参数中的s参数（如：/admin/park）
    if (urlParams.get('s')) {
        var sParam = urlParams.get('s');
        var parts = sParam.split('/');
        if (parts.length >= 3) {
            currentController = parts[2]; // admin后面的控制器名
            currentAction = parts[3] || 'index'; // 方法名，默认index
        }
    } else {
        // 如果没有s参数，从路径中解析
        var pathParts = currentPath.split('/');
        if (pathParts.length >= 3) {
            currentController = pathParts[2];
            currentAction = pathParts[3] || 'index';
        }
    }
    
    console.log('当前控制器:', currentController, '当前方法:', currentAction);
    
    // 遍历所有菜单项进行匹配
    $('.layui-nav-tree a').each(function(){
        var $this = $(this);
        var href = $this.attr('href');
        var isMatched = false;
        
        if (href && href !== 'javascript:;') {
            // 处理完整URL匹配
            if (href.indexOf('http') === 0) {
                if (currentUrl === href) {
                    isMatched = true;
                }
            } else {
                // 处理相对路径匹配
                if (href.indexOf('?s=') !== -1) {
                    // 解析href中的s参数
                    var hrefUrl = new URL(href, window.location.origin);
                    var hrefS = hrefUrl.searchParams.get('s');
                    if (hrefS) {
                        var hrefParts = hrefS.split('/');
                        if (hrefParts.length >= 3) {
                            var hrefController = hrefParts[2];
                            var hrefAction = hrefParts[3] || 'index';
                            
                            // 精确匹配控制器
                            if (currentController === hrefController) {
                                // 如果是同一个控制器，进一步检查方法
                                if (hrefAction === 'index' || currentAction === hrefAction) {
                                    isMatched = true;
                                }
                            }
                        }
                    }
                } else {
                    // 传统路径匹配
                    if (currentPath.indexOf(href) === 0) {
                        isMatched = true;
                    }
                }
            }
        }
        
        if (isMatched) {
            $this.parent().addClass('layui-this');
            $this.parents('.layui-nav-item').addClass('layui-nav-itemed');
            console.log('匹配到菜单:', href);
        }
    });
    
    // 监听导航点击事件，确保菜单正常工作
    element.on('nav(nav)', function(elem){
        // 菜单点击事件处理
        console.log('菜单点击：', elem);
    });
    
    // 确保所有有子菜单的项目都能正常展开
    $('.layui-nav-tree .layui-nav-item').each(function(){
        var $this = $(this);
        if($this.find('.layui-nav-child').length > 0){
            $this.find('> a').off('click').on('click', function(e){
                e.preventDefault();
                
                // 切换展开状态
                if($this.hasClass('layui-nav-itemed')){
                    $this.removeClass('layui-nav-itemed');
                } else {
                    $this.addClass('layui-nav-itemed');
                }
                
                return false;
            });
        }
    });
});
</script>
</body>
</html>